/*
 * @Author: 刘美红 liumeihong@llootong.com
 * @Date: 2025-04-07 09:55:59
 * @LastEditors: 刘美红 liumeihong@llootong.com
 * @LastEditTime: 2025-04-14 20:02:44
 * @FilePath: \gzt-template\src\utils\minxin.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, onMounted, onUnmounted } from 'vue';
import dayjs from 'dayjs';
export function Minxfun() {
  function errorImg(e) {
    let img = e.srcElement;
    img.src = '';
    img.onerror = null;
  }

  const formatDateTime = (time) => {
    if (time) {
      return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
    } else {
      return '--';
    }
  };

  function toTopScroll(dom, speed) {
    let timer = setInterval(() => {
      if (dom.scrollTop <= 0) {
        clearInterval(timer);
        dom.scrollTop = 0;
      }
      dom.scrollTop = dom.scrollTop - 30;
    }, 30);
  }

  let showpreve = ref(false);
  let urlCatch = ref([]);

  let showImg = (url) => {
    console.log('sssssssssssss', url);

    if (!url) {
      return;
    }
    urlCatch.value[0] = url;
    showpreve.value = true;
  };

  // 分页大小改变
  let total = ref(0);
  let tableField = ref({
    pageNo: 1,
    pageSize: 20,
  });

  const handleSizeChange = (pageSize) => {
    tableField.value = {
      pageSize,
      pageNo: 1,
    };
  };

  // 分页页数改变
  const handleCurrentChange = (currentPage) => {
    tableField.value = {
      ...tableField.value,
      pageNo: currentPage,
    };
  };

  let loading = ref(false);

  return {
    loading,
    errorImg,
    toTopScroll,
    showpreve,
    urlCatch,
    showImg,
    handleSizeChange,
    handleCurrentChange,
    tableField,
    total,
    formatDateTime,
  };
}
